!pip install cartopy
!pip install pycountry
!pip install geopandas
!pip install --upgrade plotly-express
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import cartopy.crs as ccrs
import cartopy.feature as cfeature
df = pd.read_csv('world_population.csv')
num_filas = len(df)
num_columnas = len(df.columns)
print("Número de filas:", num_filas)
print("Número de columnas:", num_columnas)
df
Número de filas: 234 Número de columnas: 17
| Rank | CCA3 | Country/Territory | Capital | Continent | 2022 Population | 2020 Population | 2015 Population | 2010 Population | 2000 Population | 1990 Population | 1980 Population | 1970 Population | Area (km²) | Density (per km²) | Growth Rate | World Population Percentage | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 36 | AFG | Afghanistan | Kabul | Asia | 41128771 | 38972230 | 33753499 | 28189672 | 19542982 | 10694796 | 12486631 | 10752971 | 652230 | 63.0587 | 1.0257 | 0.52 |
| 1 | 138 | ALB | Albania | Tirana | Europe | 2842321 | 2866849 | 2882481 | 2913399 | 3182021 | 3295066 | 2941651 | 2324731 | 28748 | 98.8702 | 0.9957 | 0.04 |
| 2 | 34 | DZA | Algeria | Algiers | Africa | 44903225 | 43451666 | 39543154 | 35856344 | 30774621 | 25518074 | 18739378 | 13795915 | 2381741 | 18.8531 | 1.0164 | 0.56 |
| 3 | 213 | ASM | American Samoa | Pago Pago | Oceania | 44273 | 46189 | 51368 | 54849 | 58230 | 47818 | 32886 | 27075 | 199 | 222.4774 | 0.9831 | 0.00 |
| 4 | 203 | AND | Andorra | Andorra la Vella | Europe | 79824 | 77700 | 71746 | 71519 | 66097 | 53569 | 35611 | 19860 | 468 | 170.5641 | 1.0100 | 0.00 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 229 | 226 | WLF | Wallis and Futuna | Mata-Utu | Oceania | 11572 | 11655 | 12182 | 13142 | 14723 | 13454 | 11315 | 9377 | 142 | 81.4930 | 0.9953 | 0.00 |
| 230 | 172 | ESH | Western Sahara | El Aaiún | Africa | 575986 | 556048 | 491824 | 413296 | 270375 | 178529 | 116775 | 76371 | 266000 | 2.1654 | 1.0184 | 0.01 |
| 231 | 46 | YEM | Yemen | Sanaa | Asia | 33696614 | 32284046 | 28516545 | 24743946 | 18628700 | 13375121 | 9204938 | 6843607 | 527968 | 63.8232 | 1.0217 | 0.42 |
| 232 | 63 | ZMB | Zambia | Lusaka | Africa | 20017675 | 18927715 | 16248230 | 13792086 | 9891136 | 7686401 | 5720438 | 4281671 | 752612 | 26.5976 | 1.0280 | 0.25 |
| 233 | 74 | ZWE | Zimbabwe | Harare | Africa | 16320537 | 15669666 | 14154937 | 12839771 | 11834676 | 10113893 | 7049926 | 5202918 | 390757 | 41.7665 | 1.0204 | 0.20 |
234 rows × 17 columns
import pandas as pd
import pycountry
def get_alpha_3(location):
try:
return pycountry.countries.get(name=location).alpha_3
except:
return None
df['Code']=df['Country/Territory'].apply(lambda x: get_alpha_3(x))
print(df.head(6))
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) Cell In[10], line 2 1 import pandas as pd ----> 2 import pycountry 3 def get_alpha_3(location): 4 try: ModuleNotFoundError: No module named 'pycountry'
import plotly.express as px
figura=px.choropleth(df,locations='Code',
color='Area (km²)',hover_name='Country/Territory',
color_continuous_scale=px.colors.sequential.Plasma)
figura.show()
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[11], line 2 1 import plotly.express as px ----> 2 figura=px.choropleth(df,locations='Code', 3 color='Area (km²)',hover_name='Country/Territory', 4 color_continuous_scale=px.colors.sequential.Plasma) 5 figura.show() File C:\ProgramData\anaconda3\Lib\site-packages\plotly\express\_chart_types.py:1091, in choropleth(data_frame, lat, lon, locations, locationmode, geojson, featureidkey, color, facet_row, facet_col, facet_col_wrap, facet_row_spacing, facet_col_spacing, hover_name, hover_data, custom_data, animation_frame, animation_group, category_orders, labels, color_discrete_sequence, color_discrete_map, color_continuous_scale, range_color, color_continuous_midpoint, projection, scope, center, fitbounds, basemap_visible, title, template, width, height) 1051 def choropleth( 1052 data_frame=None, 1053 lat=None, (...) 1085 height=None, 1086 ) -> go.Figure: 1087 """ 1088 In a choropleth map, each row of `data_frame` is represented by a 1089 colored region mark on a map. 1090 """ -> 1091 return make_figure( 1092 args=locals(), 1093 constructor=go.Choropleth, 1094 trace_patch=dict(locationmode=locationmode), 1095 ) File C:\ProgramData\anaconda3\Lib\site-packages\plotly\express\_core.py:1990, in make_figure(args, constructor, trace_patch, layout_patch) 1987 layout_patch = layout_patch or {} 1988 apply_default_cascade(args) -> 1990 args = build_dataframe(args, constructor) 1991 if constructor in [go.Treemap, go.Sunburst, go.Icicle] and args["path"] is not None: 1992 args = process_dataframe_hierarchy(args) File C:\ProgramData\anaconda3\Lib\site-packages\plotly\express\_core.py:1405, in build_dataframe(args, constructor) 1402 args["color"] = None 1403 # now that things have been prepped, we do the systematic rewriting of `args` -> 1405 df_output, wide_id_vars = process_args_into_dataframe( 1406 args, wide_mode, var_name, value_name 1407 ) 1409 # now that `df_output` exists and `args` contains only references, we complete 1410 # the special-case and wide-mode handling by further rewriting args and/or mutating 1411 # df_output 1413 count_name = _escape_col_name(df_output, "count", [var_name, value_name]) File C:\ProgramData\anaconda3\Lib\site-packages\plotly\express\_core.py:1207, in process_args_into_dataframe(args, wide_mode, var_name, value_name) 1205 if argument == "index": 1206 err_msg += "\n To use the index, pass it in directly as `df.index`." -> 1207 raise ValueError(err_msg) 1208 elif length and len(df_input[argument]) != length: 1209 raise ValueError( 1210 "All arguments should have the same length. " 1211 "The length of column argument `df[%s]` is %d, whereas the " (...) 1218 ) 1219 ) ValueError: Value of 'locations' is not the name of a column in 'data_frame'. Expected one of ['Rank', 'CCA3', 'Country/Territory', 'Capital', 'Continent', '2022 Population', '2020 Population', '2015 Population', '2010 Population', '2000 Population', '1990 Population', '1980 Population', '1970 Population', 'Area (km²)', 'Density (per km²)', 'Growth Rate', 'World Population Percentage'] but received: Code
import plotly.express as px
figura=px.choropleth(df,locations='Code',
color='Density (per km²)',hover_name='Country/Territory',
color_continuous_scale=px.colors.sequential.Plasma)
figura.show()
estadisticas_descriptivas = df.describe() #generar estadísticas
estadisticas_descriptivas.rename(index={ #traducir a español
'count': 'conteo',
'mean': 'media',
'std': 'desviación estándar',
'min': 'mínimo',
'25%': 'percentil 25',
'50%': 'percentil 50 (mediana)',
'75%': 'percentil 75',
'max': 'máximo',
}, inplace=True)
# Eliminar notación científica con ceros
pd.options.display.float_format = '{:.2f}'.format
estadisticas_descriptivas
| Rank | 2022 Population | 2020 Population | 2015 Population | 2010 Population | 2000 Population | 1990 Population | 1980 Population | 1970 Population | Area (km²) | Density (per km²) | Growth Rate | World Population Percentage | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| conteo | 234.00 | 234.00 | 234.00 | 234.00 | 234.00 | 234.00 | 234.00 | 234.00 | 234.00 | 234.00 | 234.00 | 234.00 | 234.00 |
| media | 117.50 | 34074414.71 | 33501070.95 | 31729956.24 | 29845235.03 | 26269468.82 | 22710220.79 | 18984616.97 | 15786908.81 | 581449.38 | 452.13 | 1.01 | 0.43 |
| desviación estándar | 67.69 | 136766424.80 | 135589876.92 | 130404992.75 | 124218487.63 | 111698206.72 | 97832173.35 | 81785186.08 | 67795091.64 | 1761840.86 | 2066.12 | 0.01 | 1.71 |
| mínimo | 1.00 | 510.00 | 520.00 | 564.00 | 596.00 | 651.00 | 700.00 | 733.00 | 752.00 | 1.00 | 0.03 | 0.91 | 0.00 |
| percentil 25 | 59.25 | 419738.50 | 415284.50 | 404676.00 | 393149.00 | 327242.00 | 264115.75 | 229614.25 | 155997.00 | 2650.00 | 38.42 | 1.00 | 0.01 |
| percentil 50 (mediana) | 117.50 | 5559944.50 | 5493074.50 | 5307400.00 | 4942770.50 | 4292907.00 | 3825409.50 | 3141145.50 | 2604830.00 | 81199.50 | 95.35 | 1.01 | 0.07 |
| percentil 75 | 175.75 | 22476504.75 | 21447979.50 | 19730853.75 | 19159567.50 | 15762301.00 | 11869231.00 | 9826053.75 | 8817329.00 | 430425.75 | 238.93 | 1.02 | 0.28 |
| máximo | 234.00 | 1425887337.00 | 1424929781.00 | 1393715448.00 | 1348191368.00 | 1264099069.00 | 1153704252.00 | 982372466.00 | 822534450.00 | 17098242.00 | 23172.27 | 1.07 | 17.88 |
df_europa = df.loc[df['Continent'] == 'Europe']
#df_europa.describe()
#df_europa
# Crear una figura y ejes para los subgráficos
fig, axs = plt.subplots(8, 1, figsize=(20, 80), sharex=True)
# Lista de años
years = ['1970', '1980', '1990', '2000', '2010', '2015', '2020', '2022']
# Iterar sobre cada año y crear un gráfico para ese año
for i, year in enumerate(years):
# Seleccionar los datos correspondientes al año
df_year = df_europa[['Country/Territory', f'{year} Population']]
df_year_sorted = df_year.sort_values(by=f'{year} Population', ascending=False)
# Crear el gráfico de barras para el año actual
axs[i].barh(df_year_sorted['Country/Territory'], df_year_sorted[f'{year} Population'], color='skyblue')
axs[i].set_xlabel(f'Población en {year}')
axs[i].set_ylabel('País')
axs[i].set_title(f'Población total de cada país en Europa en {year}')
axs[i].invert_yaxis() # Invertir el eje y para ordenar de mayor a menor
# Ajustar el espaciado entre los subgráficos
plt.tight_layout()
# Mostrar la figura
plt.show()
df_asia = df.loc[df['Continent'] == 'Asia']
df_asia
| Rank | CCA3 | Country/Territory | Capital | Continent | 2022 Population | 2020 Population | 2015 Population | 2010 Population | 2000 Population | 1990 Population | 1980 Population | 1970 Population | Area (km²) | Density (per km²) | Growth Rate | World Population Percentage | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 36 | AFG | Afghanistan | Kabul | Asia | 41128771 | 38972230 | 33753499 | 28189672 | 19542982 | 10694796 | 12486631 | 10752971 | 652230 | 63.06 | 1.03 | 0.52 |
| 9 | 140 | ARM | Armenia | Yerevan | Asia | 2780469 | 2805608 | 2878595 | 2946293 | 3168523 | 3556539 | 3135123 | 2534377 | 29743 | 93.48 | 1.00 | 0.03 |
| 13 | 91 | AZE | Azerbaijan | Baku | Asia | 10358074 | 10284951 | 9863480 | 9237202 | 8190337 | 7427836 | 6383060 | 5425317 | 86600 | 119.61 | 1.00 | 0.13 |
| 15 | 154 | BHR | Bahrain | Manama | Asia | 1472233 | 1477469 | 1362142 | 1213645 | 711442 | 517418 | 362595 | 222555 | 765 | 1924.49 | 1.01 | 0.02 |
| 16 | 8 | BGD | Bangladesh | Dhaka | Asia | 171186372 | 167420951 | 157830000 | 148391139 | 129193327 | 107147651 | 83929765 | 67541860 | 147570 | 1160.04 | 1.01 | 2.15 |
| 23 | 165 | BTN | Bhutan | Thimphu | Asia | 782455 | 772506 | 743274 | 705516 | 587207 | 558442 | 415257 | 298894 | 38394 | 20.38 | 1.01 | 0.01 |
| 29 | 175 | BRN | Brunei | Bandar Seri Begawan | Asia | 449002 | 441725 | 421437 | 396053 | 333926 | 261928 | 187921 | 133343 | 5765 | 77.88 | 1.01 | 0.01 |
| 33 | 73 | KHM | Cambodia | Phnom Penh | Asia | 16767842 | 16396860 | 15417523 | 14363532 | 12118841 | 8910808 | 6198959 | 6708525 | 181035 | 92.62 | 1.01 | 0.21 |
| 41 | 1 | CHN | China | Beijing | Asia | 1425887337 | 1424929781 | 1393715448 | 1348191368 | 1264099069 | 1153704252 | 982372466 | 822534450 | 9706961 | 146.89 | 1.00 | 17.88 |
| 73 | 131 | GEO | Georgia | Tbilisi | Asia | 3744385 | 3765912 | 3771132 | 3836831 | 4265172 | 5391636 | 5145843 | 4800426 | 69700 | 53.72 | 1.00 | 0.05 |
| 89 | 104 | HKG | Hong Kong | Hong Kong | Asia | 7488865 | 7500958 | 7399838 | 7132438 | 6731195 | 5838574 | 4978544 | 3955072 | 1104 | 6783.39 | 1.00 | 0.09 |
| 92 | 2 | IND | India | New Delhi | Asia | 1417173173 | 1396387127 | 1322866505 | 1240613620 | 1059633675 | 870452165 | 696828385 | 557501301 | 3287590 | 431.07 | 1.01 | 17.77 |
| 93 | 4 | IDN | Indonesia | Jakarta | Asia | 275501339 | 271857970 | 259091970 | 244016173 | 214072421 | 182159874 | 148177096 | 115228394 | 1904569 | 144.65 | 1.01 | 3.45 |
| 94 | 17 | IRN | Iran | Tehran | Asia | 88550570 | 87290193 | 81790841 | 75373855 | 65544383 | 55793629 | 38520664 | 28449705 | 1648195 | 53.73 | 1.01 | 1.11 |
| 95 | 35 | IRQ | Iraq | Baghdad | Asia | 44496122 | 42556984 | 37757813 | 31264875 | 24628858 | 17658381 | 13653369 | 9811347 | 438317 | 101.52 | 1.02 | 0.56 |
| 98 | 98 | ISR | Israel | Jerusalem | Asia | 9038309 | 8757489 | 8007778 | 7328445 | 6116958 | 4803254 | 3744608 | 2907307 | 20770 | 435.16 | 1.02 | 0.11 |
| 102 | 11 | JPN | Japan | Tokyo | Asia | 123951692 | 125244761 | 127250933 | 128105431 | 126803861 | 123686321 | 117624196 | 105416839 | 377930 | 327.98 | 0.99 | 1.55 |
| 104 | 83 | JOR | Jordan | Amman | Asia | 11285869 | 10928721 | 9494246 | 6931258 | 5056174 | 3480587 | 2216903 | 1557374 | 89342 | 126.32 | 1.01 | 0.14 |
| 105 | 66 | KAZ | Kazakhstan | Nursultan | Asia | 19397998 | 18979243 | 17835909 | 16627837 | 15236253 | 16866563 | 14172710 | 12265305 | 2724900 | 7.12 | 1.01 | 0.24 |
| 108 | 129 | KWT | Kuwait | Kuwait City | Asia | 4268873 | 4360444 | 3908743 | 2943356 | 1934901 | 1674938 | 1493870 | 802786 | 17818 | 239.58 | 1.00 | 0.05 |
| 109 | 110 | KGZ | Kyrgyzstan | Bishkek | Asia | 6630623 | 6424874 | 5914980 | 5483774 | 4935182 | 4394734 | 3691209 | 3016384 | 199951 | 33.16 | 1.02 | 0.08 |
| 110 | 103 | LAO | Laos | Vientiane | Asia | 7529475 | 7319399 | 6787419 | 6323418 | 5430853 | 4314443 | 3297519 | 2675283 | 236800 | 31.80 | 1.01 | 0.09 |
| 112 | 119 | LBN | Lebanon | Beirut | Asia | 5489739 | 5662923 | 6398940 | 4995800 | 4320642 | 3593700 | 2963702 | 2381791 | 10452 | 525.23 | 0.98 | 0.07 |
| 119 | 167 | MAC | Macau | Concelho de Macau | Asia | 695168 | 676283 | 615239 | 557297 | 431896 | 350227 | 245332 | 247284 | 30 | 23172.27 | 1.01 | 0.01 |
| 122 | 45 | MYS | Malaysia | Kuala Lumpur | Asia | 33938221 | 33199993 | 31068833 | 28717731 | 22945150 | 17517054 | 13215707 | 10306508 | 330803 | 102.59 | 1.01 | 0.43 |
| 123 | 174 | MDV | Maldives | Malé | Asia | 523787 | 514438 | 435582 | 361575 | 282507 | 224957 | 164887 | 123243 | 300 | 1745.96 | 1.00 | 0.01 |
| 135 | 134 | MNG | Mongolia | Ulaanbaatar | Asia | 3398366 | 3294335 | 2964749 | 2702520 | 2450979 | 2161433 | 1697780 | 1293880 | 1564110 | 2.17 | 1.02 | 0.04 |
| 140 | 26 | MMR | Myanmar | Nay Pyi Taw | Asia | 54179306 | 53423198 | 51483949 | 49390988 | 45538332 | 40099553 | 33465781 | 27284112 | 676578 | 80.08 | 1.01 | 0.68 |
| 143 | 49 | NPL | Nepal | Kathmandu | Asia | 30547580 | 29348627 | 27610325 | 27161567 | 24559500 | 19616530 | 15600442 | 12501285 | 147181 | 207.55 | 1.02 | 0.38 |
| 151 | 56 | PRK | North Korea | Pyongyang | Asia | 26069416 | 25867467 | 25258015 | 24686435 | 23367059 | 20799523 | 17973650 | 14996879 | 120538 | 216.28 | 1.00 | 0.33 |
| 155 | 127 | OMN | Oman | Muscat | Asia | 4576298 | 4543399 | 4191776 | 2881914 | 2344253 | 1804524 | 1017462 | 670693 | 309500 | 14.79 | 1.01 | 0.06 |
| 156 | 5 | PAK | Pakistan | Islamabad | Asia | 235824862 | 227196741 | 210969298 | 194454498 | 154369924 | 115414069 | 80624057 | 59290872 | 881912 | 267.40 | 1.02 | 2.96 |
| 158 | 122 | PSE | Palestine | Ramallah | Asia | 5250072 | 5019401 | 4484614 | 3992278 | 3139954 | 2124609 | 1453620 | 1118241 | 6220 | 844.06 | 1.02 | 0.07 |
| 163 | 13 | PHL | Philippines | Manila | Asia | 115559009 | 112190977 | 103031365 | 94636700 | 77958223 | 61558898 | 48419546 | 37435586 | 342353 | 337.54 | 1.01 | 1.45 |
| 167 | 143 | QAT | Qatar | Doha | Asia | 2695122 | 2760385 | 2414573 | 1713504 | 645937 | 441675 | 277450 | 118007 | 11586 | 232.62 | 1.00 | 0.03 |
| 182 | 41 | SAU | Saudi Arabia | Riyadh | Asia | 36408820 | 35997107 | 32749848 | 29411929 | 21547390 | 16004763 | 10171710 | 6106191 | 2149690 | 16.94 | 1.01 | 0.46 |
| 187 | 113 | SGP | Singapore | Singapore | Asia | 5975689 | 5909869 | 5650018 | 5163590 | 4053602 | 3022209 | 2400729 | 2061831 | 710 | 8416.46 | 1.01 | 0.07 |
| 194 | 29 | KOR | South Korea | Seoul | Asia | 51815810 | 51844690 | 50994401 | 48813042 | 46788591 | 44120039 | 38170501 | 32601143 | 100210 | 517.07 | 1.00 | 0.65 |
| 197 | 61 | LKA | Sri Lanka | Colombo | Asia | 21832143 | 21715079 | 21336697 | 20668557 | 18776371 | 17204094 | 14943645 | 12388769 | 65610 | 332.76 | 1.00 | 0.27 |
| 202 | 60 | SYR | Syria | Damascus | Asia | 22125249 | 20772595 | 19205178 | 22337563 | 16307654 | 12408996 | 8898954 | 6319199 | 185180 | 119.48 | 1.04 | 0.28 |
| 203 | 57 | TWN | Taiwan | Taipei | Asia | 23893394 | 23821464 | 23512136 | 23083083 | 22194731 | 20586174 | 18100281 | 14957870 | 36193 | 660.17 | 1.00 | 0.30 |
| 204 | 95 | TJK | Tajikistan | Dushanbe | Asia | 9952787 | 9543207 | 8524063 | 7621779 | 6272998 | 5417860 | 4045965 | 2993019 | 143100 | 69.55 | 1.02 | 0.12 |
| 206 | 20 | THA | Thailand | Bangkok | Asia | 71697030 | 71475664 | 70294397 | 68270489 | 63066603 | 55228410 | 45737753 | 35791728 | 513120 | 139.73 | 1.00 | 0.90 |
| 207 | 155 | TLS | Timor-Leste | Dili | Asia | 1341296 | 1299995 | 1205813 | 1088486 | 878360 | 758106 | 642224 | 554021 | 14874 | 90.18 | 1.02 | 0.02 |
| 213 | 18 | TUR | Turkey | Ankara | Asia | 85341241 | 84135428 | 79646178 | 73195345 | 64113547 | 54324142 | 44089069 | 35540990 | 783562 | 108.91 | 1.01 | 1.07 |
| 214 | 111 | TKM | Turkmenistan | Ashgabat | Asia | 6430770 | 6250438 | 5766431 | 5267970 | 4569132 | 3720278 | 2862903 | 2201432 | 488100 | 13.18 | 1.01 | 0.08 |
| 219 | 97 | ARE | United Arab Emirates | Abu Dhabi | Asia | 9441129 | 9287289 | 8916899 | 8481771 | 3275333 | 1900151 | 1014048 | 298084 | 83600 | 112.93 | 1.01 | 0.12 |
| 224 | 43 | UZB | Uzbekistan | Tashkent | Asia | 34627652 | 33526656 | 30949417 | 28614227 | 24925554 | 20579100 | 15947129 | 12011361 | 447400 | 77.40 | 1.02 | 0.43 |
| 228 | 16 | VNM | Vietnam | Hanoi | Asia | 98186856 | 96648685 | 92191398 | 87411012 | 79001142 | 66912613 | 52968270 | 41928849 | 331212 | 296.45 | 1.01 | 1.23 |
| 231 | 46 | YEM | Yemen | Sanaa | Asia | 33696614 | 32284046 | 28516545 | 24743946 | 18628700 | 13375121 | 9204938 | 6843607 | 527968 | 63.82 | 1.02 | 0.42 |
# Crear una figura y ejes para los subgráficos
fig, axs = plt.subplots(8, 1, figsize=(20, 80), sharex=True)
# Lista de años
years = ['1970', '1980', '1990', '2000', '2010', '2015', '2020', '2022']
# Iterar sobre cada año y crear un gráfico para ese año
for i, year in enumerate(years):
# Seleccionar los datos correspondientes al año
df_year = df_asia[['Country/Territory', f'{year} Population']]
df_year_sorted = df_year.sort_values(by=f'{year} Population', ascending=False)
# Crear el gráfico de barras para el año actual
axs[i].barh(df_year_sorted['Country/Territory'], df_year_sorted[f'{year} Population'], color='skyblue')
axs[i].set_xlabel(f'Población en {year}')
axs[i].set_ylabel('País')
axs[i].set_title(f'Población total de cada país en Asia en {year}')
axs[i].invert_yaxis() # Invertir el eje y para ordenar de mayor a menor
# Ajustar el espaciado entre los subgráficos
plt.tight_layout()
# Mostrar la figura
plt.show()
!pip install plotly.express
Collecting plotly.express Downloading plotly_express-0.4.1-py2.py3-none-any.whl (2.9 kB) Requirement already satisfied: pandas>=0.20.0 in /usr/local/lib/python3.10/dist-packages (from plotly.express) (1.5.3) Requirement already satisfied: plotly>=4.1.0 in /usr/local/lib/python3.10/dist-packages (from plotly.express) (5.15.0) Requirement already satisfied: statsmodels>=0.9.0 in /usr/local/lib/python3.10/dist-packages (from plotly.express) (0.14.1) Requirement already satisfied: scipy>=0.18 in /usr/local/lib/python3.10/dist-packages (from plotly.express) (1.11.4) Requirement already satisfied: patsy>=0.5 in /usr/local/lib/python3.10/dist-packages (from plotly.express) (0.5.6) Requirement already satisfied: numpy>=1.11 in /usr/local/lib/python3.10/dist-packages (from plotly.express) (1.25.2) Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=0.20.0->plotly.express) (2.8.2) Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=0.20.0->plotly.express) (2023.4) Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from patsy>=0.5->plotly.express) (1.16.0) Requirement already satisfied: tenacity>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from plotly>=4.1.0->plotly.express) (8.2.3) Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from plotly>=4.1.0->plotly.express) (24.0) Installing collected packages: plotly.express Successfully installed plotly.express-0.4.1
import plotly.express as px
import pandas as pd
df_asia.rename(columns={"Country/Territory": "pais", "World Population Percentage": "Poblacion_mundial"}, inplace=True)
fig = px.line(df_asia, x="pais", y="Poblacion_mundial")
fig.show()
C:\Users\Juan Felipe\AppData\Local\Temp\ipykernel_11852\2786135486.py:3: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
df_asia.rename(columns={"Country/Territory": "pais", "World Population Percentage": "Poblacion_mundial"}, inplace=True)
df_africa = df.loc[df['Continent'] == 'Africa']
df_africa
| Rank | CCA3 | Country/Territory | Capital | Continent | 2022 Population | 2020 Population | 2015 Population | 2010 Population | 2000 Population | 1990 Population | 1980 Population | 1970 Population | Area (km²) | Density (per km²) | Growth Rate | World Population Percentage | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2 | 34 | DZA | Algeria | Algiers | Africa | 44903225 | 43451666 | 39543154 | 35856344 | 30774621 | 25518074 | 18739378 | 13795915 | 2381741 | 18.85 | 1.02 | 0.56 |
| 5 | 42 | AGO | Angola | Luanda | Africa | 35588987 | 33428485 | 28127721 | 23364185 | 16394062 | 11828638 | 8330047 | 6029700 | 1246700 | 28.55 | 1.03 | 0.45 |
| 21 | 77 | BEN | Benin | Porto-Novo | Africa | 13352864 | 12643123 | 10932783 | 9445710 | 6998023 | 5133419 | 3833939 | 3023443 | 112622 | 118.56 | 1.03 | 0.17 |
| 26 | 144 | BWA | Botswana | Gaborone | Africa | 2630296 | 2546402 | 2305171 | 2091664 | 1726985 | 1341474 | 938578 | 592244 | 582000 | 4.52 | 1.02 | 0.03 |
| 31 | 58 | BFA | Burkina Faso | Ouagadougou | Africa | 22673762 | 21522626 | 18718019 | 16116845 | 11882888 | 9131361 | 6932967 | 5611666 | 272967 | 83.06 | 1.03 | 0.28 |
| 32 | 78 | BDI | Burundi | Bujumbura | Africa | 12889576 | 12220227 | 10727148 | 9126605 | 6307659 | 5483793 | 4312834 | 3497834 | 27834 | 463.09 | 1.03 | 0.16 |
| 34 | 53 | CMR | Cameroon | Yaounde | Africa | 27914536 | 26491087 | 23012646 | 19878036 | 15091594 | 11430520 | 8519891 | 6452787 | 475442 | 58.71 | 1.03 | 0.35 |
| 36 | 171 | CPV | Cape Verde | Praia | Africa | 593149 | 582640 | 552166 | 521212 | 458251 | 364563 | 317234 | 287262 | 4033 | 147.07 | 1.01 | 0.01 |
| 38 | 117 | CAF | Central African Republic | Bangui | Africa | 5579144 | 5343020 | 4819333 | 4660067 | 3759170 | 2809221 | 2415276 | 2067356 | 622984 | 8.96 | 1.02 | 0.07 |
| 39 | 69 | TCD | Chad | N'Djamena | Africa | 17723315 | 16644701 | 14140274 | 11894727 | 8259137 | 5827069 | 4408230 | 3667394 | 1284000 | 13.80 | 1.03 | 0.22 |
| 43 | 163 | COM | Comoros | Moroni | Africa | 836774 | 806166 | 730216 | 656024 | 536758 | 431119 | 328328 | 242351 | 1862 | 449.40 | 1.02 | 0.01 |
| 52 | 160 | DJI | Djibouti | Djibouti | Africa | 1120849 | 1090156 | 1006259 | 919199 | 742033 | 577173 | 324121 | 144379 | 23200 | 48.31 | 1.01 | 0.01 |
| 55 | 15 | COD | DR Congo | Kinshasa | Africa | 99010212 | 92853164 | 78656904 | 66391257 | 48616317 | 35987541 | 26708686 | 20151733 | 2344858 | 42.22 | 1.03 | 1.24 |
| 57 | 14 | EGY | Egypt | Cairo | Africa | 110990103 | 107465134 | 97723799 | 87252413 | 71371371 | 57214630 | 43748556 | 34781986 | 1002450 | 110.72 | 1.02 | 1.39 |
| 59 | 152 | GNQ | Equatorial Guinea | Malabo | Africa | 1674908 | 1596049 | 1346973 | 1094524 | 684977 | 465549 | 282509 | 316955 | 28051 | 59.71 | 1.02 | 0.02 |
| 60 | 132 | ERI | Eritrea | Asmara | Africa | 3684032 | 3555868 | 3340006 | 3147727 | 2392880 | 2149960 | 1657982 | 1272748 | 117600 | 31.33 | 1.02 | 0.05 |
| 62 | 159 | SWZ | Eswatini | Mbabane | Africa | 1201670 | 1180655 | 1133936 | 1099920 | 1030496 | 854011 | 598564 | 442865 | 17364 | 69.20 | 1.01 | 0.02 |
| 63 | 12 | ETH | Ethiopia | Addis Ababa | Africa | 123379924 | 117190911 | 102471895 | 89237791 | 67031867 | 47878073 | 34945469 | 28308246 | 1104300 | 111.73 | 1.03 | 1.55 |
| 71 | 146 | GAB | Gabon | Libreville | Africa | 2388992 | 2292573 | 2028517 | 1711105 | 1272935 | 983028 | 749078 | 597192 | 267668 | 8.93 | 1.02 | 0.03 |
| 72 | 142 | GMB | Gambia | Banjul | Africa | 2705992 | 2573995 | 2253133 | 1937275 | 1437539 | 1040616 | 718586 | 528731 | 10689 | 253.16 | 1.02 | 0.03 |
| 75 | 47 | GHA | Ghana | Accra | Africa | 33475870 | 32180401 | 28870939 | 25574719 | 19665502 | 15446982 | 11865246 | 8861895 | 238533 | 140.34 | 1.02 | 0.42 |
| 84 | 75 | GIN | Guinea | Conakry | Africa | 13859341 | 13205153 | 11625998 | 10270728 | 8336967 | 6354145 | 4972609 | 4222374 | 245857 | 56.37 | 1.02 | 0.17 |
| 85 | 149 | GNB | Guinea-Bissau | Bissau | Africa | 2105566 | 2015828 | 1788919 | 1567220 | 1230849 | 973551 | 831462 | 591663 | 36125 | 58.29 | 1.02 | 0.03 |
| 100 | 52 | CIV | Ivory Coast | Yamoussoukro | Africa | 28160542 | 26811790 | 23596741 | 21120042 | 16799670 | 11910540 | 8303809 | 5477086 | 322463 | 87.33 | 1.02 | 0.35 |
| 106 | 27 | KEN | Kenya | Nairobi | Africa | 54027487 | 51985780 | 46851488 | 41517895 | 30851606 | 23162269 | 16187124 | 11473087 | 580367 | 93.09 | 1.02 | 0.68 |
| 113 | 147 | LSO | Lesotho | Maseru | Africa | 2305825 | 2254100 | 2118521 | 2022747 | 1998630 | 1798997 | 1407672 | 1023481 | 30355 | 75.96 | 1.01 | 0.03 |
| 114 | 121 | LBR | Liberia | Monrovia | Africa | 5302681 | 5087584 | 4612329 | 4019956 | 2895224 | 2209731 | 1932169 | 1463563 | 111369 | 47.61 | 1.02 | 0.07 |
| 115 | 107 | LBY | Libya | Tripoli | Africa | 6812341 | 6653942 | 6192235 | 6491988 | 5154790 | 4236983 | 2962720 | 1909177 | 1759540 | 3.87 | 1.01 | 0.09 |
| 120 | 50 | MDG | Madagascar | Antananarivo | Africa | 29611714 | 28225177 | 24850912 | 21731053 | 16216431 | 11882762 | 8948162 | 6639751 | 587041 | 50.44 | 1.02 | 0.37 |
| 121 | 62 | MWI | Malawi | Lilongwe | Africa | 20405317 | 19377061 | 16938942 | 14718422 | 11229387 | 9539665 | 6267369 | 4625141 | 118484 | 172.22 | 1.03 | 0.26 |
| 124 | 59 | MLI | Mali | Bamako | Africa | 22593590 | 21224040 | 18112907 | 15529181 | 11239101 | 8945026 | 7372581 | 6153587 | 1240192 | 18.22 | 1.03 | 0.28 |
| 128 | 126 | MRT | Mauritania | Nouakchott | Africa | 4736139 | 4498604 | 3946220 | 3419461 | 2695003 | 2006027 | 1506694 | 1122198 | 1030700 | 4.60 | 1.03 | 0.06 |
| 129 | 157 | MUS | Mauritius | Port Louis | Africa | 1299469 | 1297828 | 1293153 | 1283330 | 1215930 | 1090290 | 954865 | 830115 | 2040 | 636.99 | 1.00 | 0.02 |
| 130 | 182 | MYT | Mayotte | Mamoudzou | Africa | 326101 | 305587 | 249545 | 211786 | 159215 | 92659 | 52233 | 35383 | 374 | 871.93 | 1.03 | 0.00 |
| 138 | 40 | MAR | Morocco | Rabat | Africa | 37457971 | 36688772 | 34680458 | 32464865 | 28554415 | 24570814 | 19678444 | 15274351 | 446550 | 83.88 | 1.01 | 0.47 |
| 139 | 48 | MOZ | Mozambique | Maputo | Africa | 32969517 | 31178239 | 26843246 | 23073723 | 17768505 | 13303459 | 11413587 | 8411676 | 801590 | 41.13 | 1.03 | 0.41 |
| 141 | 145 | NAM | Namibia | Windhoek | Africa | 2567012 | 2489098 | 2282704 | 2099271 | 1819141 | 1369011 | 975994 | 754467 | 825615 | 3.11 | 1.01 | 0.03 |
| 148 | 54 | NER | Niger | Niamey | Africa | 26207977 | 24333639 | 20128124 | 16647543 | 11622665 | 8370647 | 6173177 | 4669708 | 1267000 | 20.69 | 1.04 | 0.33 |
| 149 | 6 | NGA | Nigeria | Abuja | Africa | 218541212 | 208327405 | 183995785 | 160952853 | 122851984 | 95214257 | 72951439 | 55569264 | 923768 | 236.58 | 1.02 | 2.74 |
| 168 | 114 | COG | Republic of the Congo | Brazzaville | Africa | 5970424 | 5702174 | 5064386 | 4437884 | 3134030 | 2385435 | 1829256 | 1396989 | 342000 | 17.46 | 1.02 | 0.07 |
| 169 | 161 | REU | Reunion | Saint-Denis | Africa | 974052 | 957822 | 922495 | 890130 | 785424 | 658992 | 551674 | 473925 | 2511 | 387.91 | 1.01 | 0.01 |
| 172 | 76 | RWA | Rwanda | Kigali | Africa | 13776698 | 13146362 | 11642959 | 10309031 | 8109989 | 7319962 | 5247532 | 3896367 | 26338 | 523.07 | 1.02 | 0.17 |
| 181 | 187 | STP | Sao Tome and Principe | São Tomé | Africa | 227380 | 218641 | 201124 | 182138 | 143714 | 120343 | 97210 | 77583 | 964 | 235.87 | 1.02 | 0.00 |
| 183 | 72 | SEN | Senegal | Dakar | Africa | 17316449 | 16436119 | 14356181 | 12530121 | 9704287 | 7536001 | 5703869 | 4367744 | 196722 | 88.03 | 1.03 | 0.22 |
| 185 | 196 | SYC | Seychelles | Victoria | Africa | 107118 | 105530 | 99240 | 92409 | 80060 | 71057 | 65290 | 54379 | 452 | 236.99 | 1.01 | 0.00 |
| 186 | 102 | SLE | Sierra Leone | Freetown | Africa | 8605718 | 8233969 | 7314773 | 6436698 | 4584067 | 4325388 | 3367477 | 2778557 | 71740 | 119.96 | 1.02 | 0.11 |
| 192 | 70 | SOM | Somalia | Mogadishu | Africa | 17597511 | 16537016 | 13763906 | 12026649 | 8721465 | 6999096 | 5892224 | 3720977 | 637657 | 27.60 | 1.03 | 0.22 |
| 193 | 24 | ZAF | South Africa | Pretoria | Africa | 59893885 | 58801927 | 55876504 | 51784921 | 46813266 | 39877570 | 29463549 | 22368306 | 1221037 | 49.05 | 1.01 | 0.75 |
| 195 | 86 | SSD | South Sudan | Juba | Africa | 10913164 | 10606227 | 11194299 | 9714419 | 6114440 | 4750817 | 4192011 | 3342410 | 619745 | 17.61 | 1.02 | 0.14 |
| 198 | 32 | SDN | Sudan | Khartoum | Africa | 46874204 | 44440486 | 38171178 | 33739933 | 26298773 | 21090886 | 16673586 | 11305206 | 1886068 | 24.85 | 1.03 | 0.59 |
| 205 | 22 | TZA | Tanzania | Dodoma | Africa | 65497748 | 61704518 | 52542823 | 45110527 | 34463704 | 26206012 | 19297659 | 13618192 | 945087 | 69.30 | 1.03 | 0.82 |
| 208 | 100 | TGO | Togo | Lomé | Africa | 8848699 | 8442580 | 7473229 | 6571855 | 5008035 | 3875947 | 2838110 | 2197383 | 56785 | 155.83 | 1.02 | 0.11 |
| 212 | 79 | TUN | Tunisia | Tunis | Africa | 12356117 | 12161723 | 11557779 | 10895063 | 9893316 | 8440023 | 6578156 | 5047404 | 163610 | 75.52 | 1.01 | 0.15 |
| 217 | 31 | UGA | Uganda | Kampala | Africa | 47249585 | 44404611 | 37477356 | 32341728 | 24020697 | 17586630 | 13284026 | 10317212 | 241550 | 195.61 | 1.03 | 0.59 |
| 230 | 172 | ESH | Western Sahara | El Aaiún | Africa | 575986 | 556048 | 491824 | 413296 | 270375 | 178529 | 116775 | 76371 | 266000 | 2.17 | 1.02 | 0.01 |
| 232 | 63 | ZMB | Zambia | Lusaka | Africa | 20017675 | 18927715 | 16248230 | 13792086 | 9891136 | 7686401 | 5720438 | 4281671 | 752612 | 26.60 | 1.03 | 0.25 |
| 233 | 74 | ZWE | Zimbabwe | Harare | Africa | 16320537 | 15669666 | 14154937 | 12839771 | 11834676 | 10113893 | 7049926 | 5202918 | 390757 | 41.77 | 1.02 | 0.20 |
# Crear una figura y ejes para los subgráficos
fig, axs = plt.subplots(8, 1, figsize=(20, 80), sharex=True)
# Lista de años
years = ['1970', '1980', '1990', '2000', '2010', '2015', '2020', '2022']
# Iterar sobre cada año y crear un gráfico para ese año
for i, year in enumerate(years):
# Seleccionar los datos correspondientes al año
df_year = df_africa[['Country/Territory', f'{year} Population']]
df_year_sorted = df_year.sort_values(by=f'{year} Population', ascending=False)
# Crear el gráfico de barras para el año actual
axs[i].barh(df_year_sorted['Country/Territory'], df_year_sorted[f'{year} Population'], color='skyblue')
axs[i].set_xlabel(f'Población en {year}')
axs[i].set_ylabel('País')
axs[i].set_title(f'Población total de cada país en Africa en {year}')
axs[i].invert_yaxis() # Invertir el eje y para ordenar de mayor a menor
# Ajustar el espaciado entre los subgráficos
plt.tight_layout()
# Mostrar la figura
plt.show()
df_north_america = df.loc[df['Continent'] == 'North America']
df_north_america
| Rank | CCA3 | Country/Territory | Capital | Continent | 2022 Population | 2020 Population | 2015 Population | 2010 Population | 2000 Population | 1990 Population | 1980 Population | 1970 Population | Area (km²) | Density (per km²) | Growth Rate | World Population Percentage | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 6 | 224 | AIA | Anguilla | The Valley | North America | 15857 | 15585 | 14525 | 13172 | 11047 | 8316 | 6560 | 6283 | 91 | 174.25 | 1.01 | 0.00 |
| 7 | 201 | ATG | Antigua and Barbuda | Saint John’s | North America | 93763 | 92664 | 89941 | 85695 | 75055 | 63328 | 64888 | 64516 | 442 | 212.13 | 1.01 | 0.00 |
| 10 | 198 | ABW | Aruba | Oranjestad | North America | 106445 | 106585 | 104257 | 100341 | 89101 | 65712 | 62267 | 59106 | 180 | 591.36 | 1.00 | 0.00 |
| 14 | 176 | BHS | Bahamas | Nassau | North America | 409984 | 406471 | 392697 | 373272 | 325014 | 270679 | 223752 | 179129 | 13943 | 29.40 | 1.01 | 0.01 |
| 17 | 186 | BRB | Barbados | Bridgetown | North America | 281635 | 280693 | 278083 | 274711 | 264657 | 258868 | 253575 | 241397 | 430 | 654.97 | 1.00 | 0.00 |
| 20 | 177 | BLZ | Belize | Belmopan | North America | 405272 | 394921 | 359871 | 322106 | 240406 | 182589 | 145133 | 120905 | 22966 | 17.65 | 1.01 | 0.01 |
| 22 | 206 | BMU | Bermuda | Hamilton | North America | 64184 | 64031 | 63144 | 63447 | 61371 | 57470 | 53565 | 52019 | 54 | 1188.59 | 1.00 | 0.00 |
| 28 | 221 | VGB | British Virgin Islands | Road Town | North America | 31305 | 30910 | 29366 | 27556 | 20104 | 15617 | 11109 | 9581 | 151 | 207.32 | 1.01 | 0.00 |
| 35 | 39 | CAN | Canada | Ottawa | North America | 38454327 | 37888705 | 35732126 | 33963412 | 30683313 | 27657204 | 24511510 | 21434577 | 9984670 | 3.85 | 1.01 | 0.48 |
| 37 | 205 | CYM | Cayman Islands | George Town | North America | 68706 | 67311 | 60911 | 54074 | 39658 | 26027 | 17100 | 10533 | 264 | 260.25 | 1.01 | 0.00 |
| 45 | 124 | CRI | Costa Rica | San José | North America | 5180829 | 5123105 | 4895242 | 4622252 | 3979193 | 3158253 | 2414303 | 1855697 | 51100 | 101.39 | 1.01 | 0.06 |
| 47 | 85 | CUB | Cuba | Havana | North America | 11212191 | 11300698 | 11339894 | 11290417 | 11105791 | 10626680 | 9809107 | 8869636 | 109884 | 102.04 | 1.00 | 0.14 |
| 48 | 189 | CUW | Curacao | Willemstad | North America | 191163 | 189288 | 169572 | 159380 | 141424 | 155446 | 156851 | 150385 | 444 | 430.55 | 1.00 | 0.00 |
| 53 | 204 | DMA | Dominica | Roseau | North America | 72737 | 71995 | 70007 | 68755 | 68346 | 69481 | 72978 | 68895 | 751 | 96.85 | 1.00 | 0.00 |
| 54 | 84 | DOM | Dominican Republic | Santo Domingo | North America | 11228821 | 10999664 | 10405832 | 9775755 | 8540791 | 7129004 | 5755800 | 4475871 | 48671 | 230.71 | 1.01 | 0.14 |
| 58 | 112 | SLV | El Salvador | San Salvador | North America | 6336392 | 6292731 | 6231066 | 6114034 | 5958482 | 5367179 | 4508992 | 3619090 | 21041 | 301.14 | 1.00 | 0.08 |
| 78 | 208 | GRL | Greenland | Nuuk | North America | 56466 | 56026 | 55895 | 56351 | 56184 | 55599 | 50106 | 45434 | 2166086 | 0.03 | 1.00 | 0.00 |
| 79 | 193 | GRD | Grenada | Saint George's | North America | 125438 | 123663 | 118980 | 114039 | 107432 | 99047 | 94838 | 98794 | 344 | 364.65 | 1.01 | 0.00 |
| 80 | 178 | GLP | Guadeloupe | Basse-Terre | North America | 395752 | 395642 | 399089 | 403072 | 424067 | 391951 | 334234 | 318310 | 1628 | 243.09 | 1.00 | 0.00 |
| 82 | 68 | GTM | Guatemala | Guatemala City | North America | 17843908 | 17362718 | 16001107 | 14543121 | 11735894 | 9084780 | 6987767 | 5453208 | 108889 | 163.87 | 1.01 | 0.22 |
| 87 | 82 | HTI | Haiti | Port-au-Prince | North America | 11584996 | 11306801 | 10563757 | 9842880 | 8360225 | 6925331 | 5646676 | 4680812 | 27750 | 417.48 | 1.01 | 0.15 |
| 88 | 89 | HND | Honduras | Tegucigalpa | North America | 10432860 | 10121763 | 9294505 | 8450933 | 6656725 | 5053234 | 3777990 | 2782753 | 112492 | 92.74 | 1.01 | 0.13 |
| 101 | 139 | JAM | Jamaica | Kingston | North America | 2827377 | 2820436 | 2794445 | 2733896 | 2612205 | 2392030 | 2135546 | 1859091 | 10991 | 257.24 | 1.00 | 0.04 |
| 127 | 180 | MTQ | Martinique | Fort-de-France | North America | 367507 | 370391 | 383515 | 392181 | 432543 | 374271 | 333786 | 326428 | 1128 | 325.80 | 1.00 | 0.00 |
| 131 | 10 | MEX | Mexico | Mexico City | North America | 127504125 | 125998302 | 120149897 | 112532401 | 97873442 | 81720428 | 67705186 | 50289306 | 1964375 | 64.91 | 1.01 | 1.60 |
| 137 | 230 | MSR | Montserrat | Brades | North America | 4390 | 4500 | 5059 | 4938 | 5138 | 10805 | 11452 | 11402 | 102 | 43.04 | 0.99 | 0.00 |
| 147 | 106 | NIC | Nicaragua | Managua | North America | 6948392 | 6755895 | 6298598 | 5855734 | 5123222 | 4227820 | 3303309 | 2444767 | 130373 | 53.30 | 1.01 | 0.09 |
| 159 | 128 | PAN | Panama | Panama City | North America | 4408581 | 4294396 | 3957099 | 3623617 | 3001731 | 2449968 | 1956987 | 1516188 | 75417 | 58.46 | 1.01 | 0.06 |
| 166 | 136 | PRI | Puerto Rico | San Juan | North America | 3252407 | 3271564 | 3497335 | 3717922 | 3827108 | 3543776 | 3214568 | 2737619 | 8870 | 366.68 | 1.00 | 0.04 |
| 173 | 228 | BLM | Saint Barthelemy | Gustavia | North America | 10967 | 10681 | 9643 | 8988 | 7082 | 5168 | 2983 | 2417 | 21 | 522.24 | 1.01 | 0.00 |
| 174 | 211 | KNA | Saint Kitts and Nevis | Basseterre | North America | 47657 | 47642 | 47790 | 47403 | 45461 | 40636 | 43097 | 44968 | 261 | 182.59 | 1.00 | 0.00 |
| 175 | 190 | LCA | Saint Lucia | Castries | North America | 179857 | 179237 | 175623 | 170935 | 159500 | 142301 | 121633 | 103090 | 616 | 291.98 | 1.00 | 0.00 |
| 176 | 220 | MAF | Saint Martin | Marigot | North America | 31791 | 32552 | 35020 | 36458 | 29610 | 28127 | 7776 | 5802 | 53 | 599.83 | 1.00 | 0.00 |
| 177 | 229 | SPM | Saint Pierre and Miquelon | Saint-Pierre | North America | 5862 | 5906 | 5978 | 6052 | 6274 | 6324 | 6106 | 5537 | 242 | 24.22 | 1.00 | 0.00 |
| 178 | 199 | VCT | Saint Vincent and the Grenadines | Kingstown | North America | 103948 | 104632 | 106482 | 109308 | 113813 | 112487 | 107480 | 98459 | 389 | 267.22 | 1.00 | 0.00 |
| 188 | 214 | SXM | Sint Maarten | Philipsburg | North America | 44175 | 43621 | 40205 | 33034 | 30489 | 27845 | 12243 | 6260 | 34 | 1299.26 | 1.00 | 0.00 |
| 211 | 153 | TTO | Trinidad and Tobago | Port-of-Spain | North America | 1531044 | 1518147 | 1460177 | 1410296 | 1332203 | 1266518 | 1127852 | 988890 | 5130 | 298.45 | 1.00 | 0.02 |
| 215 | 212 | TCA | Turks and Caicos Islands | Cockburn Town | North America | 45703 | 44276 | 36538 | 29726 | 18744 | 11709 | 7598 | 5665 | 948 | 48.21 | 1.01 | 0.00 |
| 221 | 3 | USA | United States | Washington, D.C. | North America | 338289857 | 335942003 | 324607776 | 311182845 | 282398554 | 248083732 | 223140018 | 200328340 | 9372610 | 36.09 | 1.00 | 4.24 |
| 222 | 200 | VIR | United States Virgin Islands | Charlotte Amalie | North America | 99465 | 100442 | 102803 | 106142 | 108185 | 100685 | 96640 | 63446 | 347 | 286.64 | 0.99 | 0.00 |
# Crear una figura y ejes para los subgráficos
fig, axs = plt.subplots(8, 1, figsize=(20, 80), sharex=True)
# Lista de años
years = ['1970', '1980', '1990', '2000', '2010', '2015', '2020', '2022']
# Iterar sobre cada año y crear un gráfico para ese año
for i, year in enumerate(years):
# Seleccionar los datos correspondientes al año
df_year = df_north_america[['Country/Territory', f'{year} Population']]
df_year_sorted = df_year.sort_values(by=f'{year} Population', ascending=False)
# Crear el gráfico de barras para el año actual
axs[i].barh(df_year_sorted['Country/Territory'], df_year_sorted[f'{year} Population'], color='skyblue')
axs[i].set_xlabel(f'Población en {year}')
axs[i].set_ylabel('País')
axs[i].set_title(f'Población total de cada país en Norte America en {year}')
axs[i].invert_yaxis() # Invertir el eje y para ordenar de mayor a menor
# Ajustar el espaciado entre los subgráficos
plt.tight_layout()
# Mostrar la figura
plt.show()
df_america_sur = df.loc[df['Continent'] == 'South America']
df_america_sur
| Rank | CCA3 | Country/Territory | Capital | Continent | 2022 Population | 2020 Population | 2015 Population | 2010 Population | 2000 Population | 1990 Population | 1980 Population | 1970 Population | Area (km²) | Density (per km²) | Growth Rate | World Population Percentage | Code | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 8 | 33 | ARG | Argentina | Buenos Aires | South America | 45510318 | 45036032 | 43257065 | 41100123 | 37070774 | 32637657 | 28024803 | 23842803 | 2780400 | 16.37 | 1.01 | 0.57 | ARG |
| 24 | 80 | BOL | Bolivia | Sucre | South America | 12224110 | 11936162 | 11090085 | 10223270 | 8592656 | 7096194 | 5736088 | 4585693 | 1098581 | 11.13 | 1.01 | 0.15 | None |
| 27 | 7 | BRA | Brazil | Brasilia | South America | 215313498 | 213196304 | 205188205 | 196353492 | 175873720 | 150706446 | 122288383 | 96369875 | 8515767 | 25.28 | 1.00 | 2.70 | BRA |
| 40 | 65 | CHL | Chile | Santiago | South America | 19603733 | 19300315 | 17870124 | 17004162 | 15351799 | 13342868 | 11469828 | 9820481 | 756102 | 25.93 | 1.01 | 0.25 | CHL |
| 42 | 28 | COL | Colombia | Bogota | South America | 51874024 | 50930662 | 47119728 | 44816108 | 39215135 | 32601393 | 26176195 | 20905254 | 1141748 | 45.43 | 1.01 | 0.65 | COL |
| 56 | 67 | ECU | Ecuador | Quito | South America | 18001000 | 17588595 | 16195902 | 14989585 | 12626507 | 10449837 | 8135845 | 6172215 | 276841 | 65.02 | 1.01 | 0.23 | ECU |
| 64 | 231 | FLK | Falkland Islands | Stanley | South America | 3780 | 3747 | 3408 | 3187 | 3080 | 2332 | 2240 | 2274 | 12173 | 0.31 | 1.00 | 0.00 | None |
| 69 | 184 | GUF | French Guiana | Cayenne | South America | 304557 | 290969 | 257026 | 228453 | 164351 | 113931 | 66825 | 46484 | 83534 | 3.65 | 1.02 | 0.00 | GUF |
| 86 | 164 | GUY | Guyana | Georgetown | South America | 808726 | 797202 | 755031 | 747932 | 759051 | 747116 | 778176 | 705261 | 214969 | 3.76 | 1.01 | 0.01 | GUY |
| 161 | 109 | PRY | Paraguay | Asunción | South America | 6780744 | 6618695 | 6177950 | 5768613 | 5123819 | 4059195 | 3078912 | 2408787 | 406752 | 16.67 | 1.01 | 0.09 | PRY |
| 162 | 44 | PER | Peru | Lima | South America | 34049588 | 33304756 | 30711863 | 29229572 | 26654439 | 22109099 | 17492406 | 13562371 | 1285216 | 26.49 | 1.01 | 0.43 | PER |
| 199 | 170 | SUR | Suriname | Paramaribo | South America | 618040 | 607065 | 575475 | 546080 | 478998 | 412756 | 375112 | 379918 | 163820 | 3.77 | 1.01 | 0.01 | SUR |
| 223 | 133 | URY | Uruguay | Montevideo | South America | 3422794 | 3429086 | 3402818 | 3352651 | 3292224 | 3117012 | 2953750 | 2790265 | 181034 | 18.91 | 1.00 | 0.04 | URY |
| 227 | 51 | VEN | Venezuela | Caracas | South America | 28301696 | 28490453 | 30529716 | 28715022 | 24427729 | 19750579 | 15210443 | 11355475 | 916445 | 30.88 | 1.00 | 0.35 | None |
# Crear una figura y ejes para los subgráficos
fig, axs = plt.subplots(8, 1, figsize=(20, 80), sharex=True)
# Lista de años
years = ['1970', '1980', '1990', '2000', '2010', '2015', '2020', '2022']
# Iterar sobre cada año y crear un gráfico para ese año
for i, year in enumerate(years):
# Seleccionar los datos correspondientes al año
df_year = df_america_sur[['Country/Territory', f'{year} Population']]
df_year_sorted = df_year.sort_values(by=f'{year} Population', ascending=False)
# Crear el gráfico de barras para el año actual
axs[i].barh(df_year_sorted['Country/Territory'], df_year_sorted[f'{year} Population'], color='skyblue')
axs[i].set_xlabel(f'Población en {year}')
axs[i].set_ylabel('País')
axs[i].set_title(f'Población total de cada país en Sur america en {year}')
axs[i].invert_yaxis() # Invertir el eje y para ordenar de mayor a menor
# Ajustar el espaciado entre los subgráficos
plt.tight_layout()
# Mostrar la figura
plt.show()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[27], line 10 7 # Iterar sobre cada año y crear un gráfico para ese año 8 for i, year in enumerate(years): 9 # Seleccionar los datos correspondientes al año ---> 10 df_year = df_america_sur[['Country/Territory', f'{year} Population']] 11 df_year_sorted = df_year.sort_values(by=f'{year} Population', ascending=False) 13 # Crear el gráfico de barras para el año actual NameError: name 'df_america_sur' is not defined
df_oceania = df.loc[df['Continent'] == 'Oceania']
df_oceania
# Crear una figura y ejes para los subgráficos
fig, axs = plt.subplots(8, 1, figsize=(20, 80), sharex=True)
# Lista de años
years = ['1970', '1980', '1990', '2000', '2010', '2015', '2020', '2022']
# Iterar sobre cada año y crear un gráfico para ese año
for i, year in enumerate(years):
# Seleccionar los datos correspondientes al año
df_year = df_oceania[['Country/Territory', f'{year} Population']]
df_year_sorted = df_year.sort_values(by=f'{year} Population', ascending=False)
# Crear el gráfico de barras para el año actual
axs[i].barh(df_year_sorted['Country/Territory'], df_year_sorted[f'{year} Population'], color='skyblue')
axs[i].set_xlabel(f'Población en {year}')
axs[i].set_ylabel('País')
axs[i].set_title(f'Población total de cada país en Oceania en {year}')
axs[i].invert_yaxis() # Invertir el eje y para ordenar de mayor a menor
# Ajustar el espaciado entre los subgráficos
plt.tight_layout()
# Mostrar la figura
plt.show()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[28], line 10 7 # Iterar sobre cada año y crear un gráfico para ese año 8 for i, year in enumerate(years): 9 # Seleccionar los datos correspondientes al año ---> 10 df_year = df_oceania[['Country/Territory', f'{year} Population']] 11 df_year_sorted = df_year.sort_values(by=f'{year} Population', ascending=False) 13 # Crear el gráfico de barras para el año actual NameError: name 'df_oceania' is not defined
import plotly.express as px
df = px.data.gapminder().query("year==2007")
fig = px.choropleth(df, locations="iso_alpha",
color="lifeExp", # lifeExp is a column of gapminder
hover_name="country", # column to add to hover information
color_continuous_scale=px.colors.sequential.Plasma)
fig.show()
import plotly.express as px
import geopandas as gpd
df = px.data.election()
geo_df = gpd.GeoDataFrame.from_features(
px.data.election_geojson()["features"]
).merge(df, on="district").set_index("district")
fig = px.choropleth_mapbox(geo_df,
geojson=geo_df.geometry,
locations=geo_df.index,
color="Joly",
center={"lat": 45.5517, "lon": -73.7073},
mapbox_style="open-street-map",
zoom=8.5)
fig.show()
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv')
fig = go.Figure(data=go.Choropleth(
locations = df['CODE'],
z = df['GDP (BILLIONS)'],
text = df['COUNTRY'],
colorscale = 'Blues',
autocolorscale=False,
reversescale=True,
marker_line_color='darkgray',
marker_line_width=0.5,
colorbar_tickprefix = '$',
colorbar_title = 'GDP<br>Billions US$',
))
fig.update_layout(
title_text='2014 Global GDP',
geo=dict(
showframe=False,
showcoastlines=False,
projection_type='equirectangular'
),
annotations = [dict(
x=0.55,
y=0.1,
xref='paper',
yref='paper',
text='Source: <a href="https://www.cia.gov/library/publications/the-world-factbook/fields/2195.html">\
CIA World Factbook</a>',
showarrow = False
)]
)
fig.show()
import pandas as pd
import plotly.express as px
import json
# Cargar los datos geográficos de América del Norte desde el archivo GeoJSON local
with open('north_america_map.json') as f:
counties = json.load(f)
# Leer el archivo CSV con datos de población
df_north_america = pd.read_csv("world_population.csv", dtype={"Country/Territory": str})
# Crear el mapa coroplético
fig = px.choropleth(df_north_america, locations='Country/Territory', color='2022 Population',
color_continuous_scale="Viridis",
range_color=(0, 1000000),
scope="north america",
labels={'2022 Population':'Population'}
)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
--------------------------------------------------------------------------- UnicodeDecodeError Traceback (most recent call last) Cell In[39], line 7 5 # Cargar los datos geográficos de América del Norte desde el archivo GeoJSON local 6 with open('north_america_map.json') as f: ----> 7 counties = json.load(f) 9 # Leer el archivo CSV con datos de población 10 df_north_america = pd.read_csv("world_population.csv", dtype={"Country/Territory": str}) File C:\ProgramData\anaconda3\Lib\json\__init__.py:293, in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 274 def load(fp, *, cls=None, object_hook=None, parse_float=None, 275 parse_int=None, parse_constant=None, object_pairs_hook=None, **kw): 276 """Deserialize ``fp`` (a ``.read()``-supporting file-like object containing 277 a JSON document) to a Python object. 278 (...) 291 kwarg; otherwise ``JSONDecoder`` is used. 292 """ --> 293 return loads(fp.read(), 294 cls=cls, object_hook=object_hook, 295 parse_float=parse_float, parse_int=parse_int, 296 parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File C:\ProgramData\anaconda3\Lib\encodings\cp1252.py:23, in IncrementalDecoder.decode(self, input, final) 22 def decode(self, input, final=False): ---> 23 return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 2143: character maps to <undefined>
!pip install plotly==5.13.0
Collecting plotly==5.13.0
Downloading plotly-5.13.0-py2.py3-none-any.whl (15.2 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 15.2/15.2 MB 45.1 MB/s eta 0:00:00
Requirement already satisfied: tenacity>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from plotly==5.13.0) (8.2.3)
Installing collected packages: plotly
Attempting uninstall: plotly
Found existing installation: plotly 5.15.0
Uninstalling plotly-5.15.0:
Successfully uninstalled plotly-5.15.0
Successfully installed plotly-5.13.0
# Importar los módulos necesarios
import pandas as pd
import plotly.express as px
from urllib.request import urlopen
import json
# Cargar los datos geográficos de África desde el archivo GeoJSON
with urlopen('https://raw.githubusercontent.com/codeforamerica/click_that_hood/master/public/data/africa.geojson') as response:
counties = json.load(response)
# Leer el archivo CSV con datos de población
df_africa = pd.read_csv("world_population.csv", dtype={"Country/Territory": str})
# Crear el mapa coroplético
fig = px.choropleth(df_africa, locations='Country/Territory', color='2022 Population',
color_continuous_scale="Viridis",
range_color=(0, 1000000),
scope="africa",
labels={'2022 Population':'Population'}
)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
import pandas as pd
import plotly.express as px
import json
# Cargar los datos geográficos de América del Norte desde el archivo GeoJSON local
with open('asia_map.json') as f:
counties = json.load(f)
# Leer el archivo CSV con datos de población
df_asia = pd.read_csv("world_population.csv", dtype={"Country/Territory": str})
# Crear el mapa coroplético
fig = px.choropleth(df_asia, locations='Country/Territory', color='2022 Population',
color_continuous_scale="Viridis",
range_color=(0, 1000000),
scope="asia",
labels={'2022 Population':'Population'}
)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
--------------------------------------------------------------------------- UnicodeDecodeError Traceback (most recent call last) Cell In[38], line 7 5 # Cargar los datos geográficos de América del Norte desde el archivo GeoJSON local 6 with open('asia_map.json') as f: ----> 7 counties = json.load(f) 9 # Leer el archivo CSV con datos de población 10 df_asia = pd.read_csv("world_population.csv", dtype={"Country/Territory": str}) File C:\ProgramData\anaconda3\Lib\json\__init__.py:293, in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 274 def load(fp, *, cls=None, object_hook=None, parse_float=None, 275 parse_int=None, parse_constant=None, object_pairs_hook=None, **kw): 276 """Deserialize ``fp`` (a ``.read()``-supporting file-like object containing 277 a JSON document) to a Python object. 278 (...) 291 kwarg; otherwise ``JSONDecoder`` is used. 292 """ --> 293 return loads(fp.read(), 294 cls=cls, object_hook=object_hook, 295 parse_float=parse_float, parse_int=parse_int, 296 parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) File C:\ProgramData\anaconda3\Lib\encodings\cp1252.py:23, in IncrementalDecoder.decode(self, input, final) 22 def decode(self, input, final=False): ---> 23 return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 2125: character maps to <undefined>
import plotly.graph_objects as go
fig = go.Figure(go.Scattergeo())
fig.update_geos(projection_type="orthographic")
fig.update_layout(height=300, margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
import plotly.graph_objects as go
fig = go.Figure(go.Scattergeo())
fig.update_geos(projection_type="natural earth")
fig.update_layout(height=300, margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
# Definir el límite geográfico de Europa
europe_extent = [-20, 50, 35, 70] # [longitud mínima, longitud máxima, latitud mínima, latitud máxima]
# Crear una figura y ejes
plt.figure(figsize=(14, 10))
ax = plt.axes(projection=ccrs.PlateCarree())
# Establecer el límite geográfico del mapa a Europa
ax.set_extent(europe_extent)
# Agregar contornos de los países de Europa
ax.add_feature(cfeature.BORDERS, linestyle=':', linewidth=0.5, edgecolor='black')
# Agregar detalles adicionales, como la costa
ax.add_feature(cfeature.COASTLINE, linewidth=0.5)
# Mostrar el mapa de Europa
plt.show()
/usr/local/lib/python3.10/dist-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/50m_cultural/ne_50m_admin_0_boundary_lines_land.zip /usr/local/lib/python3.10/dist-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/50m_physical/ne_50m_coastline.zip
# Definir el límite geográfico de Europa
europe_extent = [-20, 50, 35, 70] # [longitud mínima, longitud máxima, latitud mínima, latitud máxima]
# Crear una figura y ejes
plt.figure(figsize=(14, 10))
ax = plt.axes(projection=ccrs.PlateCarree())
# Establecer el límite geográfico del mapa a Europa
ax.set_extent(europe_extent)
# Agregar contornos de los países de Europa
ax.add_feature(cfeature.BORDERS, linestyle=':', linewidth=0.5, edgecolor='black')
# Agregar detalles adicionales, como la costa
ax.add_feature(cfeature.COASTLINE, linewidth=0.5)
# Mostrar el mapa de Europa
plt.show()
# Definir el límite geográfico de América del Norte
north_america_extent = [-140, -50, 10, 80] # [longitud mínima, longitud máxima, latitud mínima, latitud máxima]
# Crear una figura y ejes
plt.figure(figsize=(12, 8))
ax = plt.axes(projection=ccrs.PlateCarree())
# Establecer el límite geográfico del mapa a América del Norte
ax.set_extent(north_america_extent)
# Agregar contornos de los países de América del Norte
ax.add_feature(cfeature.BORDERS, linestyle=':', linewidth=0.5, edgecolor='black')
# Agregar detalles adicionales, como la costa
ax.add_feature(cfeature.COASTLINE, linewidth=0.5)
# Mostrar el mapa de América del Norte
plt.show()
# Definir el límite geográfico de Asia
asia_extent = [30, 180, -10, 70] # [longitud mínima, longitud máxima, latitud mínima, latitud máxima]
# Crear una figura y ejes
plt.figure(figsize=(12, 8))
ax = plt.axes(projection=ccrs.PlateCarree())
# Establecer el límite geográfico del mapa a Asia
ax.set_extent(asia_extent)
# Agregar contornos de los países de Asia
ax.add_feature(cfeature.BORDERS, linestyle=':', linewidth=0.5, edgecolor='black')
# Agregar detalles adicionales, como la costa
ax.add_feature(cfeature.COASTLINE, linewidth=0.5)
# Mostrar el mapa de Asia
plt.show()
import pandas as pd
import plotly.express as px
from urllib.request import urlopen
import json
# Cargar los datos geográficos de Sudamérica desde el archivo GeoJSON
with urlopen('https://raw.githubusercontent.com/codeforamerica/click_that_hood/master/public/data/south-america.geojson') as response:
counties = json.load(response)
# Leer el archivo CSV con datos de población
df_africa = pd.read_csv("world_population.csv", dtype={"Country/Territory": str})
# Crear el mapa coroplético
fig = px.choropleth(df_africa, locations='Country/Territory', color='2022 Population',
color_continuous_scale="Viridis",
range_color=(0, 1000000),
scope="south america",
labels={'2022 Population':'Population'}
)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
# Definir el límite geográfico de Sudamérica
south_america_extent = [-85, -30, -60, 15] # [longitud mínima, longitud máxima, latitud mínima, latitud máxima]
# Crear una figura y ejes
plt.figure(figsize=(12, 8))
ax = plt.axes(projection=ccrs.PlateCarree())
# Establecer el límite geográfico del mapa a Sudamérica
ax.set_extent(south_america_extent)
# Agregar contornos de los países de Sudamérica
ax.add_feature(cfeature.BORDERS, linestyle=':', linewidth=0.5, edgecolor='black')
# Agregar detalles adicionales, como la costa
ax.add_feature(cfeature.COASTLINE, linewidth=0.5)
# Mostrar el mapa de Sudamérica
plt.show()
plt.figure(figsize=(12, 8))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
#plt.savefig('coastlines.pdf')
#plt.savefig('coastlines.png')
plt.show()
###################### 1970 #########################
df_europa_1970 = df_europa[['Country/Territory', '1970 Population']]
# Ordenar por población en 2022 de mayor a menor
df_europa_1970_sorted = df_europa_1970.sort_values(by='1970 Population', ascending=False)
# Crear el gráfico de barras
plt.figure(figsize=(20, 10))
plt.barh(df_europa_1970_sorted['Country/Territory'], df_europa_1970_sorted['1970 Population'], color='skyblue')
plt.barh(df_europa_1970_sorted['Country/Territory'], df_europa_1970_sorted['1970 Population'], color='skyblue')
plt.xlabel('Población en 1970')
plt.ylabel('País')
plt.title('Población total de cada país Europa en 1970')
plt.gca().invert_yaxis() # Invertir el eje y para ordenar de mayor a menor
plt.show()
###################### 1980 #########################
df_europa_1980 = df_europa[['Country/Territory', '1980 Population']]
# Ordenar por población en 2022 de mayor a menor
df_europa_1980_sorted = df_europa_1980.sort_values(by='1980 Population', ascending=False)
# Crear el gráfico de barras
plt.figure(figsize=(20, 10))
plt.barh(df_europa_1980_sorted['Country/Territory'], df_europa_1980_sorted['1980 Population'], color='skyblue')
plt.barh(df_europa_1980_sorted['Country/Territory'], df_europa_1980_sorted['1980 Population'], color='skyblue')
plt.xlabel('Población en 1980')
plt.ylabel('País')
plt.title('Población total de cada país Europa en 1980')
plt.gca().invert_yaxis() # Invertir el eje y para ordenar de mayor a menor
plt.show()
###################### 1990 #########################
df_europa_1990 = df_europa[['Country/Territory', '1990 Population']]
# Ordenar por población en 2022 de mayor a menor
df_europa_1990_sorted = df_europa_1990.sort_values(by='1990 Population', ascending=False)
# Crear el gráfico de barras
plt.figure(figsize=(20, 10))
plt.barh(df_europa_1990_sorted['Country/Territory'], df_europa_1990_sorted['1990 Population'], color='skyblue')
plt.barh(df_europa_1990_sorted['Country/Territory'], df_europa_1990_sorted['1990 Population'], color='skyblue')
plt.xlabel('Población en 1990')
plt.ylabel('País')
plt.title('Población total de cada país Europa en 1990')
plt.gca().invert_yaxis() # Invertir el eje y para ordenar de mayor a menor
plt.show()
###################### 2000 #########################
df_europa_2000 = df_europa[['Country/Territory', '2000 Population']]
# Ordenar por población en 2022 de mayor a menor
df_europa_2000_sorted = df_europa_2000.sort_values(by='2000 Population', ascending=False)
# Crear el gráfico de barras
plt.figure(figsize=(20, 10))
plt.barh(df_europa_2000_sorted['Country/Territory'], df_europa_2000_sorted['2000 Population'], color='skyblue')
plt.barh(df_europa_2000_sorted['Country/Territory'], df_europa_2000_sorted['2000 Population'], color='skyblue')
plt.xlabel('Población en 2000')
plt.ylabel('País')
plt.title('Población total de cada país Europa en 1990')
plt.gca().invert_yaxis() # Invertir el eje y para ordenar de mayor a menor
plt.show()
###################### 2010 #########################
df_europa_2010 = df_europa[['Country/Territory', '2010 Population']]
# Ordenar por población en 2010 de mayor a menor
df_europa_2010_sorted = df_europa_2010.sort_values(by='2010 Population', ascending=False)
# Crear el gráfico de barras
plt.figure(figsize=(20, 10))
plt.barh(df_europa_2010_sorted['Country/Territory'], df_europa_2010_sorted['2010 Population'], color='skyblue')
plt.barh(df_europa_2010_sorted['Country/Territory'], df_europa_2010_sorted['2010 Population'], color='skyblue')
plt.xlabel('Población en 2010')
plt.ylabel('País')
plt.title('Población total de cada país Europa en 2010')
plt.gca().invert_yaxis() # Invertir el eje y para ordenar de mayor a menor
plt.show()
###################### 2015 #########################
df_europa_2015 = df_europa[['Country/Territory', '2015 Population']]
# Ordenar por población en 2010 de mayor a menor
df_europa_2015_sorted = df_europa_2015.sort_values(by='2015 Population', ascending=False)
# Crear el gráfico de barras
plt.figure(figsize=(20, 10))
plt.barh(df_europa_2015_sorted['Country/Territory'], df_europa_2015_sorted['2015 Population'], color='skyblue')
plt.barh(df_europa_2015_sorted['Country/Territory'], df_europa_2015_sorted['2015 Population'], color='skyblue')
plt.xlabel('Población en 2015')
plt.ylabel('País')
plt.title('Población total de cada país Europa en 2015')
plt.gca().invert_yaxis() # Invertir el eje y para ordenar de mayor a menor
plt.show()
# Ordenar por población en 2020 de mayor a menor
df_europa_2020 = df_europa[['Country/Territory', '2020 Population']]
df_europa_2020_sorted = df_europa_2020.sort_values(by='2020 Population', ascending=False)
# Crear el gráfico de barras
plt.figure(figsize=(20, 10))
plt.barh(df_europa_2020_sorted['Country/Territory'], df_europa_2020_sorted['2020 Population'], color='skyblue')
plt.barh(df_europa_2020_sorted['Country/Territory'], df_europa_2020_sorted['2020 Population'], color='skyblue')
plt.xlabel('Población en 2020')
plt.ylabel('País')
plt.title('Población total de cada país Europa en 2020')
plt.gca().invert_yaxis() # Invertir el eje y para ordenar de mayor a menor
plt.show()
###################### 2022 #########################
df_europa_2022 = df_europa[['Country/Territory', '2022 Population']]
# Ordenar por población en 2022 de mayor a menor
df_europa_2022_sorted = df_europa_2022.sort_values(by='2022 Population', ascending=False)
# Crear el gráfico de barras
plt.figure(figsize=(20, 10))
plt.barh(df_europa_2022_sorted['Country/Territory'], df_europa_2022_sorted['2022 Population'], color='skyblue')
plt.barh(df_europa_2022_sorted['Country/Territory'], df_europa_2022_sorted['2022 Population'], color='skyblue')
plt.xlabel('Población en 2022')
plt.ylabel('País')
plt.title('Población total de cada país Europa en 2022')
plt.gca().invert_yaxis() # Invertir el eje y para ordenar de mayor a menor
plt.show()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-9-29a875062c50> in <cell line: 2>() 1 ###################### 1970 ######################### ----> 2 df_europa_1970 = df_europa[['Country/Territory', '1970 Population']] 3 4 # Ordenar por población en 2022 de mayor a menor 5 df_europa_1970_sorted = df_europa_1970.sort_values(by='1970 Population', ascending=False) NameError: name 'df_europa' is not defined